
// 如何使用jql触发器请参考文档：https://uniapp.dcloud.net.cn/uniCloud/jql-schema-ext.html
module.exports = { 
trigger: {
    beforeCreate: async function({
      collection,
      operation,
      addDataList,
      clientInfo
    } = {}) {
	  const db = uniCloud.database();
        const title= addDataList[0].title
		const shopId = addDataList[0].shop_id
	    const res = await db.collection('shop-categories').where({title:title,shop_id:shopId}).get({
			getOne:true
		});
        if(res.data[0]){
			throw new Error('相同名称的分类已经存在，请勿重复添加！');
		}
    }
  }
}
